/*************************************************************************
* Copyright (c) 2011 im007boy@gmail.com. All rights reserved.            *
* Use of this source code is governed by a GNU-style license that can be *
* found in the LICENSE file.                                             *
*************************************************************************/

var _gaq = null;
if (navigator.platform.indexOf('Win') == 0){
	_gaq = [];
	_gaq.push(['_setAccount', 'UA-22175231-1']);
	
	_gaq.push(['_trackPageview']);

	(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	})();
}
function ga_push(category,action,opt_label,opt_value){
	if (_gaq == null || typeof _gaq == "undefined")
		return;
		
	_gaq.push(['_trackEvent', category, action, opt_label, opt_value]);
	if (localStorage['debug_analytics'] == '1')
		console.log('_trackEvent', category, action, opt_label, opt_value);
}

chrome.extension.onRequest.addListener(
	function(request, sender, sendResponse) {
		switch (request.hope){
		case "GA":
			ga_push(request.category, request.action, request.opt_label, request.opt_value);
			sendResponse({});
			break;
		}	
});